#pragma once
// License see: https://opensource.org/licenses/MIT
// 本文件由工具自动生成, 请勿修改

#include "player_interface.h"
#include <core/rpc/rpc_interface.h>
#include <core/rpc/rpc_helper.h>

template <>
class CRmiStubWrapper<IPlayerManager> : public IRmiStubImpl
{
public:
    explicit CRmiStubWrapper(IPlayerManager* p)
        : m_p(p)
    {
        
    }
    void rc_test(int a, int b)
    {
        RemoteCallMessage call_wrapper;
        call_wrapper.set_allocated_target(new protobuf_service_token(m_token));
        call_wrapper.set_type(RPC_MSG_TYPE_REMOTE_CALL);
        call_wrapper.set_call_manager(m_p->hash_code());
        call_wrapper.set_call_func(__Player_RMI_FUNC_rc_test__);
        call_wrapper.add_params(SerializeAsString(a));
        call_wrapper.add_params(SerializeAsString(b));
        auto f = m_p->managers()->find(fist::string_hash_code("IRpcManager"));
        IRpcManager* p = static_cast<IRpcManager*>(f->second);
        p->RemoteCall(call_wrapper);
    }

    cppcoro::task<int> rc_test_co(int a, int b)
    {
        RemoteCallMessage call_wrapper;
        call_wrapper.set_allocated_target(new protobuf_service_token(m_token));
        call_wrapper.set_type(RPC_MSG_TYPE_REMOTE_CALL);
        call_wrapper.set_call_manager(m_p->hash_code());
        call_wrapper.set_call_func(__Player_RMI_FUNC_rc_test__);
        call_wrapper.add_params(SerializeAsString(a));
        call_wrapper.add_params(SerializeAsString(b));
        auto f = m_p->managers()->find(fist::string_hash_code("IRpcManager"));
        IRpcManager* p = static_cast<IRpcManager*>(f->second);
        std::string co_ret;
        co_await p->RemoteCoCall(call_wrapper, co_ret);
        co_return ParseFromString<int>(co_ret);
    }


private:
    enum RmiFuncId
    {
        __Player_RMI_FUNC_rc_test__,
    };


    void rc_test_handle(const RemoteCallMessage& call)
    {
        const auto& params = call.params();
        m_p->rc_test(ParseFromString<int>(params.Get(0)), ParseFromString<int>(params.Get(1)));
    }

    cppcoro::task<> rc_test_co_handle(const RemoteCallMessage& call, std::string& back)
    {
        const auto& params = call.params();
        back = SerializeAsString(m_p->rc_test(ParseFromString<int>(params.Get(0)), ParseFromString<int>(params.Get(1))));
        co_return;
    }


void __handle_remote_call__(const RemoteCallMessage& call) override
    {
        switch (call.call_func()) {
            case __Player_RMI_FUNC_rc_test__:
                rc_test_handle(call);
                break;
                default: break;
        }
    }


cppcoro::task<> __handle_remote_co_call__(const RemoteCallMessage& call, std::string& back) override
    {
        switch (call.call_func()) {
            case __Player_RMI_FUNC_rc_test__:
                co_await rc_test_co_handle(call, back);
                break;
                default: break;
        }
        co_return;
    }


    void set_service_token(const service_token_t& tk) override
    {
        m_token.set_type(tk.type);
        m_token.set_id(tk.id);
    }
private:
    IPlayerManager* m_p;
    protobuf_service_token m_token;
};
